package com.example.xlmkotlinwanandroid.data

import com.example.xlmkotlinwanandroid.data.remote.remotedata.RemoteData
import com.example.xlmkotlinwanandroid.data.remote.remotedata.RemoteDataSource
import com.example.xlmkotlinwanandroid.model.bean.BannerBean
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import kotlin.coroutines.CoroutineContext

/**
 *  author : cailei
 *  date : 2022/3/18
 *  description :
 */
class DataRepository(private val remoteData: RemoteDataSource, private val ioDispatcher: CoroutineContext) :
    DataRepositorySource {

    override suspend fun getBanners(): Flow<Resource<ArrayList<BannerBean>>> {
        return flow {
            emit(remoteData.getBanners())
        }.flowOn(ioDispatcher)
    }
}